package main.java.indi.zyj.c150.greedy;

public class _02_JumpGame2 {


    public int jump(int[] nums) {

        int len = nums.length;
        int maxLen = 0;
        int step = 0;
        int nextMaxLen = 0;

        for (int i = 0; i < len; i++) {
            nextMaxLen = Math.max(nums[i] + i, nextMaxLen);     //和当前可以到达的位置相比，防止出现负数
            if (i == maxLen){                               //判断是否已经可以到达数组末尾]
                maxLen = nextMaxLen;
                step++;
            }
        }
        return step;
    }

    public static void main(String[] args) {

    }
}
